package com.blog.mapper;

import com.blog.entity.article.Article;
import com.blog.entity.article.ArticleType;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ArticleMapper {

    @Select("select * from types")
    List<ArticleType> getArticleTypes();

    @Select("select * from article")
    List<Article> getArticles();

    @Select("select * from article where audit = #{audit}")
    List<Article> getArticlesByAudit(String audit);

    @Select("select * from types where tid = #{tid}")
    ArticleType getArticleTypeByTid(int tid);

    @Select("select * from article where aid = #{aid}")
    Article getArticleByAid(int aid);

    @Select("select * from article where uid = #{uid}")
    List<Article> getArticleByUid(int uid);

    @Select("select * from article where tid = #{tid} and audit = '1'")
    List<Article> getArticleByTid(int tid);

    @Insert("insert into types(type) values(#{type})")
    Integer addArticleType(String type);

    @Insert("insert into article(title, content, tid, uid) values(#{title}, #{content}, #{tid}, #{uid})")
    Integer addArticle(Article article);

    @Update("update types set type = #{type} where tid = #{tid}")
    Integer updateArticleType(ArticleType articleType);

    @Update("update article set title = #{title}, content = #{content}, tid = #{tid}, audit = #{audit}, views = #{views} where aid = #{aid}")
    Integer updateArticle(Article article);

    @Delete("delete from types where tid = #{tid}")
    Integer deleteArticleTypeByTid(int tid);

    @Delete("delete from article where aid = #{aid}")
    Integer deleteArticleByAid(int aid);

}
